layui.config({
  base: '/home_v2/common/',
}).extend({
  index: '/lib/index',
  soulTable: 'soulTable'
}).use(['table', 'index', 'soulTable', 'form', 'laytpl','laypage'])
let soulTable = layui.soulTable,
  form = layui.form,
  table = layui.table,
  laytpl = layui.laytpl,
  laypage = layui.laypage,
  element = layui.element;

var oneTypeJson=[];

// $(".layui-go-back").click(function () {
//   try {
//     parent.layui.layer.closeAll();
//   } catch (e) {
//     history.go(-1);
//   }
// });



//用户范围
form.on('checkbox(yhfw1)', function(data) {
  var twoTypeJson=[];
  if($("#yhfw").val() !=""){
    twoTypeJson = $("#yhfw").val().split(",");
  }
  if (data.elem.checked) {
    twoTypeJson.push(data.elem.value)
  } else {
    var SJson = [];
    for (var i in twoTypeJson) {
      if (twoTypeJson[i] != data.elem.value) {
        SJson.push(twoTypeJson[i])
      }
    }
    twoTypeJson = SJson;
  }
  $("#yhfw").val(twoTypeJson.join(","))
})
form.on('switch(fallSwitch)', function(data){
  if(data.elem.checked){
    $("#isStop").val(0)
  }else {
    $("#isStop").val(1)
  }
})

form.on('submit(sub_button)', function (data) {
  console.log("提交",data.field)
});


// var checkedValues = ['写作', '发呆'];
// setChecked('yhfw1', checkedValues);

//设置复选框选中状态
function setChecked(name,data){
  let json = {}
  for(let i=0;i<data.length;i++){
    json[name+"['"+data[i]+"']"] = true
  }
  form.val('editForm', json);
  form.render("checkbox")
}
